<?php

namespace App\Admin\Controllers\Bargain;

use App\Admin\Repositories\Bargain\CmcPromotionBargain;
use App\Models\Bargain\CmcPromotionBargainLaunch;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Show;


class CmcPromotionBargainController extends AdminController
{
    /**
     * Notes:
     * User: w2011344@qq.com
     * Date: 2021/7/17
     * Time: 20:50
     * @return Grid
     */

    protected function grid()
    {
        return Grid::make(new CmcPromotionBargain(), function (Grid $grid) {
            $grid->withBorder();
            $grid->filter(function ($filter) {
                $filter->panel();
                $filter->between('end_time', '')->datetime();

            });
            $grid->export()->filename('砍价活动列表');
            $grid->selector(function (Grid\Tools\Selector $selector) {
                $selector->select('bargain_time', '时间选择', [
                    0 => '全部',
                    1 => '今天',
                    2 => '昨天',
                    3 => '最近7天',
                    4 => '最近30天',
                    5 => '本月',
                    6 => '本年',
                ]);
            });
            $grid->quickSearch(['category_name', 'attr_class_name']);
            $grid->column('id')->sortable();
            $grid->column('bargain_type')->image($server = null, 110, 100);
            $grid->column('bargain_name')->editable(true);
            $grid->column('status_name')->editable(true);
            $grid->column('first_bargain_price')->editable(true);
            $grid->column('cut_num');
            $grid->column('cut_remaining');
            $grid->column('start_time');
            $grid->column('end_time')->sortable();
            $grid->column('status', '状态')->switch()->filter(
                Grid\Column\Filter\In::make([
                    0 => '已结束',
                    1 => '进行中',
                ])
            );
            $grid->column('see')->modal(function ($modal) {
                //设置弹窗标题
                $modal->title('查看详情');
                //弹窗内容
                $see_details = CmcPromotionBargainLaunch::all();
                return  view('admin/activity/promotion',compact('see_details'));

            });

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
//
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new CmcPromotionBargain(), function (Show $show) {
            $show->field('id');
            $show->field('bargain_id');
            $show->field('goods_id');
            $show->field('sku_id');
            $show->field('first_bargain_price');
            $show->field('bargain_stock');
            $show->field('floor_price');
            $show->field('bargain_name');
            $show->field('is_fenxiao');
            $show->field('buy_type');
            $show->field('bargain_type');
            $show->field('bargain_num');
            $show->field('bargain_time');
            $show->field('remark');
            $show->field('start_time');
            $show->field('end_time');
            $show->field('status');
            $show->field('status_name');
            $show->field('cut_num');
            $show->field('cut_remaining');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new CmcPromotionBargain(), function (Form $form) {

            $form->text('first_bargain_price');
            $form->text('bargain_stock');
            $form->text('floor_price');
            $form->image('bargain_type');
            $form->text('is_fenxiao');
            $form->text('buy_type');
            $form->text('bargain_name');
            $form->text('bargain_num');
            $form->text('bargain_time');
            $form->text('remark');
            $form->text('start_time');
            $form->text('end_time');
            $form->text('status');
            $form->text('status_name');
            $form->text('cut_num');
            $form->text('cut_remaining');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
